﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class CheckTouch : MonoBehaviour
{

    public Slider slider;
    public Action action;
    bool isGet = false;
    bool IsNative = false;
    int touchID = -1;


    public static void Show(Transform father)
    {
        GameObject prefab = Resources.Load<GameObject>("Prefab/ChestTouch");
        GameObject box = Instantiate(prefab);
        box.transform.SetParent(father);
        box.GetComponent<RectTransform>().offsetMax = new Vector2(0, 0);
        box.GetComponent<RectTransform>().offsetMin = new Vector2(0, 0);
        box.GetComponent<RectTransform>().localScale = new Vector3(1, 1, 1);
    }

    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void FixedUpdate()
    {
        slider.value -= 0.005f;
    }

    public void TouchCheck()
    {
        slider.value += 0.1f;
    }

    public void CheckValue()
    {
        if (slider.value >= 0.1f && !IsNative)
        {
            IsNative = true;
            //黑包原生
            if (!AdManager.Instance.ShieldAddress) AdManager.Instance.ShowNative();
        }
        if (slider.value >= 0.6f && !isGet)
        {
            isGet = true;
            //黑包视频
            if (!AdManager.Instance.ShieldAddress) AdManager.Instance.ShowVideo(() => { });
            // action();
            Invoke("des", 1);
        }
    }
    //销毁
    void des()
    {
        Destroy(gameObject);
    }
}
